/******************************************************************************
 * Copyright (C) 2015  671643387@qq.com
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 *****************************************************************************/

#include "Shared/Util/WorldPacketDump.h"
#include "Ucop/Util/String.h"
#include "Shared/Log/Log.h"
using namespace Ucop;


void DumpWorldPacket(int _ConnId, const WorldPacket *_Packet)
{
	std::string _PacketStr("");
	if (_Packet->size() > 0)
	{
		const std::uint8_t *_BytePtr = _Packet->contents();
		std::size_t _P = 0;
		while (true)
		{
			for (size_t _J = 0; _J < 16 && _P < _Packet->size(); ++_J) {
				char _Buf[0x10] = { 0 };
				Util::snprintf(_Buf, sizeof(_Buf), "%.2X ", _BytePtr[_P++]);
				_PacketStr.append(_Buf);
			}

			if (_P < _Packet->size()) {
				_PacketStr.append("\n");
				continue;
			}
			break;
		}
	}
	sLog.outDebug("%d == >\n"
		"cmd:0x%x\n"
		"size: %d\n"
		"%s",
		_ConnId, _Packet->opcode(), _Packet->size(), _PacketStr.c_str());
}